package com.lljin.study.client;

import com.lljin.study.dto.OrderDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

@FeignClient(value = "order-service", fallback = OrderServiceFeignClient.OrderServiceFallback.class)
public interface OrderServiceFeignClient {

    @GetMapping("/order/{id}")
    String order(@PathVariable(value = "id") String id);

    @GetMapping("/testHystrix/{num}")
    String testHystrix(@PathVariable(value = "num") int num);

    @PostMapping("/order")
    String insert(OrderDto orderDto);

    class OrderServiceFallback implements OrderServiceFeignClient {

        @Override
        public String order(String id) {
            return "订单查询失败";
        }

        @Override
        public String testHystrix(int num) {
            return "服务调用超时";
        }

        @Override
        public String insert(OrderDto orderDto) {
            return "插入失败!";
        }
    }
}
